/**
 *
 *
 * @export
 * @param {*} entity {user:{name:'zyj'}} / {users:[ {name:'zyj', age:30 } ]}
 * @param {((string | number)[] | readonly)} path ['user','name'] / ['users',0,'name']
 */
export function get(
  entity: any,
  path: (string | number)[] | readonly (string | number)[],
) {
  if (!path || !path.length) {
    return undefined;
  }
  let current = entity;
  for (let i = 0; i < path.length; i += 1) {
    if (current === null || current === undefined) {
      return undefined;
    }

    current = current[path[i]];
  }

  return current;
}
